package cn.bigway.app.weavingdesigner.util;

import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

import cn.bigway.app.weavingdesigner.main.WdMainFrame;

public final class WdImageViewPanelFactory {

	private static final WdImageViewPanelFactory instance = new WdImageViewPanelFactory();

	private WdImageViewPanelFactory() {
		//
	}

	public static WdImageViewPanelFactory getInstance() {
		return instance;
	}

	public WdImageViewPanel create(JFileChooser fileChooser) {
		fileChooser.showOpenDialog(WdMainFrame.getInstance());

		BufferedImage image = null;

		try {
			image = ImageIO.read(fileChooser.getSelectedFile());
		} catch (IOException e) {
			e.printStackTrace();
		}

		JPanel borderPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		return new WdImageViewPanel(borderPanel, image);
	}
}
